package com.cloud.base.threadLocal;

import com.alibaba.ttl.TransmittableThreadLocal;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadLocalMain {
    // 实现父子线程共享（父：主线程，子：主线程内new thread）
    // 整合线程池需要包装一下
    private static TransmittableThreadLocal<String> threadLocal = new TransmittableThreadLocal<>();

    private static ThreadLocal<String> local = new ThreadLocal<>();

    public static void main(String[] args) {
        threadLocal.set("a");
        local.set("b");
        new Thread(() -> {
            System.out.println(threadLocal.get());
            System.out.println(local.get());
        }).start();

        ExecutorService executorService = Executors.newCachedThreadPool();
        executorService.execute(() -> {
            System.out.println(threadLocal.get());
            System.out.println(local.get());
        });
    }
}
